<?php
/**
*	编辑文件回调
*	
*/
class editfileClassAction extends apiAction
{
	public $logincheck = false;

	
	/**
	*	编辑完成后文件
	*/
	public function backAction()
	{
		$data 	 = $this->getpostdata();
		if(isempt($data))return '没有数据';
		$filenum = $this->get('filenum');
		$fileext = $this->get('fileext');
		$uptype  = '|doc|docx|xls|xlsx|ppt|pptx|';
		if(!contain($uptype,'|'.$fileext.'|'))$fileext='doc';
		
		$filepath = ''.UPDIR.'/'.date('Y-m').'/eback_'.date('dHis').''.rand(1000,9999).'.'.$fileext.'';
		$this->rock->createtxt($filepath, base64_decode($data));
		
		return m('file')->editcall($filenum, $filepath, $fileext);
	}
	
	public function anaycallAction()
	{
		$fileid  	= (int)$this->getparams('fileid','0'); //文件ID
		$infotype  	= $this->getparams('infotype');
		$frs 	 	= m('file')->getone($fileid);
		if(!$frs)return;
		if(!$infotype)$infotype = 'editfile'; //回调类型
		
		$agentid	= $frs['agentid'];
		$agentrs 	= m('agent')->getone($agentid);
		$callurl	= arrvalue($agentrs,'callurl');
		$msg 		= 'ok';
		if(!isempt($callurl)){
			$uarr['filename'] 	= $frs['filename'];
			$uarr['filenum'] 	= $frs['filenum'];
			$uarr['filesize'] 	= $frs['filesize'];
			$uarr['fileext'] 	= $frs['fileext'];
			$uarr['filesizecn'] = $frs['filesizecn'];
			$uarr['infotype'] 	= $infotype;
			$uarr['fileid'] 	= $fileid;
			$uarr['editid'] 	= $frs['editid'];
			$uarr['editname'] 	= $frs['editname'];
			$uarr['isimg'] 		= m('file')->isimg($frs['fileext']);
			
			if($uarr['isimg']){
				$uarr['thumbpath'] 	= $frs['thumbpath'];
				if(substr($uarr['thumbpath'],0,4)!='http')$uarr['thumbpath'] = '{FILEURL}'.$uarr['thumbpath'].'';
				if(!isempt($frs['thumbpathout']))$uarr['thumbpath'] = $frs['thumbpathout'];
			}
			$msg = c('curl')->postcurl($callurl, json_encode($uarr));
		}
		return $msg;
	}
}